import React, { useEffect, useState } from "react";
import type { FormProps } from "antd";
import {
  Button,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Select,
  Switch,
  TreeSelect,
  Radio,
} from "antd";
import { addshoplist, editshoplist } from "../../api";
const Myform: React.FC<any> = (props) => {
  const onFinish: FormProps<any>["onFinish"] = async (values) => {
    if (props.title == "添加") {
      let obj = {
        ...values,
        id: new Date().getTime(),
        time: new Date().getTime(),
      };
      await addshoplist(obj);
    } else {
      let obj = {
        ...values,
        id: props.itemobj.id,
        time: props.itemobj.time,
      };
      await editshoplist(obj);
    }
    props.handleOk();
    props.getShoplist();
  };
  const [form] = Form.useForm();
  useEffect(()=>{
    form.setFieldsValue(props.itemobj)
  },[])
  return (
    <Form onFinish={onFinish} form={form}>
      <Form.Item label="优惠劵名称" name="couponName">
        <Input />
      </Form.Item>
      <Form.Item label="优惠劵面值" name="discountAmount">
        <Input />
      </Form.Item>
      <Form.Item label="优惠券最低消费" name="minSpend">
        <Input />
      </Form.Item>
      <Form.Item label="优惠券有效期限(天)" name="validityPeriod">
        <Input />
      </Form.Item>
      <Form.Item label="排序" name="sortOrder">
        <Input />
      </Form.Item>
      <Form.Item label="状态" name="status">
        <Radio.Group
          options={[
            { value: true, label: "开启" },
            { value: false, label: "结束" },
          ]}
        />
      </Form.Item>
      <Form.Item>
        <Button>取消</Button>
        <Button type="primary" htmlType="submit">
          确认
        </Button>
      </Form.Item>
    </Form>
  );
};

export default Myform;
